package com.qiyi.player.wonder.plugins.share.view.parts
{
   import com.iqiyi.components.videoshare.VideoCutTimeUI;
   import flash.utils.Timer;
   import com.qiyi.player.base.utils.Strings;
   import flash.events.TimerEvent;
   import flash.events.MouseEvent;
   import flash.text.TextFormat;
   import flash.text.TextFormatAlign;
   
   public class ShareVideoCutTime extends VideoCutTimeUI
   {
      
      public function ShareVideoCutTime(param1:Number) {
         super();
         this._totalDuration = param1;
         this._timer = new Timer(100);
         this._timer.addEventListener(TimerEvent.TIMER,this.onTimer);
         this._timer.addEventListener(TimerEvent.TIMER_COMPLETE,this.onTimerComplete);
         var _loc2_:TextFormat = new TextFormat();
         _loc2_.align = TextFormatAlign.CENTER;
         timetxt.defaultTextFormat = _loc2_;
         addBtn.addEventListener(MouseEvent.MOUSE_UP,this.onBtnUp);
         addBtn.addEventListener(MouseEvent.MOUSE_DOWN,this.onAddBtnDown);
         addBtn.addEventListener(MouseEvent.CLICK,this.onBtnClick);
         addBtn.addEventListener(MouseEvent.MOUSE_OUT,this.onBtnOut);
         subBtn.addEventListener(MouseEvent.MOUSE_UP,this.onBtnUp);
         subBtn.addEventListener(MouseEvent.MOUSE_DOWN,this.onSubBtnDown);
         subBtn.addEventListener(MouseEvent.CLICK,this.onBtnClick);
         subBtn.addEventListener(MouseEvent.MOUSE_OUT,this.onBtnOut);
      }
      
      private var _totalDuration:Number = 0;
      
      private var _curTime:Number = 0;
      
      private var _variation:int = 0;
      
      private var _timer:Timer;
      
      public function get curTime() : Number {
         return this._curTime;
      }
      
      public function setTime(param1:Number) : void {
         this._curTime = param1;
         if(this._curTime < 0)
         {
            this._curTime = 0;
         }
         if(this._curTime > this._totalDuration)
         {
            this._curTime = this._totalDuration;
         }
         if(this._totalDuration >= 3600000)
         {
            timetxt.text = Strings.formatAsTimeCode(this._curTime / 1000,true);
         }
         else
         {
            timetxt.text = Strings.formatAsTimeCode(this._curTime / 1000,false);
         }
      }
      
      private function onTimer(param1:TimerEvent) : void {
         this.setTime(this._curTime = this._curTime + this._variation);
         var _loc2_:VideoShareEvent = new VideoShareEvent(VideoShareEvent.Evt_TryCutTimeChange);
         _loc2_.tryTimeOK = false;
         dispatchEvent(_loc2_);
      }
      
      private function onTimerComplete(param1:TimerEvent) : void {
         this._timer.repeatCount = 0;
         this._timer.delay = 50;
         this._timer.start();
      }
      
      private function onBtnUp(param1:MouseEvent) : void {
         if(this._timer.running)
         {
            this._timer.stop();
         }
         this.setTime(this._curTime = this._curTime + this._variation);
         var _loc2_:VideoShareEvent = new VideoShareEvent(VideoShareEvent.Evt_TryCutTimeChange);
         _loc2_.tryTimeOK = true;
         dispatchEvent(_loc2_);
      }
      
      private function onBtnClick(param1:MouseEvent) : void {
         if(this._timer.running)
         {
            this._timer.stop();
         }
      }
      
      private function onBtnOut(param1:MouseEvent) : void {
         var _loc2_:VideoShareEvent = null;
         if(this._timer.running)
         {
            this._timer.stop();
            _loc2_ = new VideoShareEvent(VideoShareEvent.Evt_TryCutTimeChange);
            _loc2_.tryTimeOK = true;
            dispatchEvent(_loc2_);
         }
      }
      
      private function onAddBtnDown(param1:MouseEvent) : void {
         this._variation = 1000;
         this._timer.repeatCount = 1;
         this._timer.delay = 700;
         this._timer.start();
         dispatchEvent(new VideoShareEvent(VideoShareEvent.Evt_TryCutTimeStart));
      }
      
      private function onSubBtnDown(param1:MouseEvent) : void {
         this._variation = -1000;
         this._timer.repeatCount = 1;
         this._timer.delay = 1000;
         this._timer.start();
         dispatchEvent(new VideoShareEvent(VideoShareEvent.Evt_TryCutTimeStart));
      }
      
      public function destory() : void {
         this._timer.removeEventListener(TimerEvent.TIMER,this.onTimer);
         this._timer.removeEventListener(TimerEvent.TIMER_COMPLETE,this.onTimerComplete);
         if(this._timer.running)
         {
            this._timer.stop();
         }
      }
   }
}
